IOStream: Input/Output from file
Parameters
wThe default mode for opening a file with ofstream's constructor is to create it if it does not exist, or delete everything in it if something does exist in it. The other arguments that specify how the file should be handled are listed below:

ios::app Opens the file, and allows additions at the end
ios::ate  Opens the file, but allows additions anywhere
ios::trunc  Deletes everything in the file
ios::nocreate  Does not open if the file must be created
ios::noreplace Does not open if the file already exists

EXAMPLE:
w ofstream a_file("test.txt", ios::nocreate);
In this case the constructor for both classes will actually open the file if you pass the name as an argument. As well, both classes have an open command (a_file.open()) and a close command (a_file.close()). It is generally a good idea to clean up after yourself and close files once you are finished.